/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nc.kyiv.yellow.sociallibrary.helper.web;

import com.nc.kyiv.yellow.sociallibrary.beans.user.UserBeanLocal;
import com.nc.kyiv.yellow.sociallibrary.beans.user.UserBeanLocalHome;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author My
 */
public class SaveToDataBaseHelper {
    
    private static final UserBeanLocal USER_BEAN = lookupUserBeanLocal();
    static final String PASS_VALUE = "111";
    
    public static void saveUser(Map parsedData){
        Map paramsRegistration = new HashMap<String, String>();
        paramsRegistration.put("login", parsedData.get("uid"));
        paramsRegistration.put("pass", PASS_VALUE);
        paramsRegistration.put("last_name", parsedData.get("last_name"));
        paramsRegistration.put("first_name", parsedData.get("first_name"));
        paramsRegistration.put("email", "testVk@vk.vk");
        USER_BEAN.registerUserWithSocNetwork(paramsRegistration);
    }
        
    private static UserBeanLocal lookupUserBeanLocal() {
        try {
            Context c = new InitialContext();
            UserBeanLocalHome rv = (UserBeanLocalHome) c.lookup("java:comp/env/UserBean");
            return rv.create();
        } catch (NamingException ne) {
            throw new RuntimeException(ne);
        } catch (CreateException ce) {
            throw new RuntimeException(ce);
        }
    }
    
    
    
}
